<template>
  <div>
    <textarea name="" v-model="txt" :placeholder="place" style="width:100%" rows="10"></textarea>
    <div>
      <a-button type="primary" @click="columns" style="marginRight:20px">转换为columns</a-button>
      <a-button type="primary" @click="formInfo" style="marginRight:20px">转换为formInfo</a-button>
      <a-button type="primary" @click="formData" style="marginRight:20px">转换为formData</a-button>
      <a-button type="primary" @click="listInfo" style="marginRight:20px">转换为listInfo</a-button>
    </div>
    <textarea name="" v-model="res" placeholder="结果" style="width:100%" rows="15"></textarea>
  </div>
</template>

<script>

export default {
  data() {
    return {
      obj: [],
      txt: '',
      res:null,
      place: `格式：{
        sysSeq: '主键编号-必须',
        pid: '对象标识-必须',
        orgPid: '所属单位',
        customerOrgPid: '采购单位Pid',
        customerCode: '采购单位编码',
        customerName: '采购单位名称',
        deliveryTime: '发货时间',
        receiptTime: '收货时间'
      }`
    }
  },
  methods: {
    columns() {
      let i=0
      let result = []
      let btn = {
          title: '操作',
          dataIndex: 'action',
          key: 'operation',
          width: 180,
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      let obj = JSON.parse(this.txt)
      for (let ind in obj) {
        i++
        let resItem = { title: '', dataIndex: '', key: '', align: 'center' }
        resItem.title = obj[ind]
        resItem.dataIndex = ind
        resItem.key = ind
        result.push(resItem)
        
      }
      result.push(btn) 
      this.res = JSON.stringify(result)
    },
    formInfo() {
      let i=0
      let result = []
      let btn = { label: ['保存', '重置'], type: 'botton' }
      let obj = JSON.parse(this.txt)
      for (let ind in obj) {
        i++
        let resItem = { label: '', name: '', type: 'input', placeholder: '' }
        resItem.label = obj[ind]
        resItem.name = ind
        resItem.placeholder = '请输入'+obj[ind]
        result.push(resItem)
      }
      result.push(btn)
      this.res = JSON.stringify(result)
    },
    formData() {
      let result = {}
      let obj = JSON.parse(this.txt)
      for (let ind in obj) {
        obj[ind]=null
      }
      this.res = JSON.stringify(obj)
    },
    listInfo() {
      let result = []
      let obj = JSON.parse(this.txt)
      for (let ind in obj) {
        let resItem = { title: '', id: '', value:''}
        resItem.title = obj[ind]
        resItem.id = ind
        result.push(resItem)
      }
      this.res = JSON.stringify(result)
    }
  }
}
</script>

<style></style>
